package day19.zhiyou200;

public class Site implements Runnable{
    // 定义票的数量
    int count = 10;
    // 定义购买了第几张票
    int sum = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (count == 0) {
                    break;
                }
                count--;
                sum++;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"购买了第" + sum + "票,剩余"+ count + "张票");
            }
        }
    }


}

class Demo001{
    public static void main(String[] args) {
        Site site = new Site();
        Thread t1 = new Thread(site,"001");
        Thread t2 = new Thread(site,"002");
        Thread t3 = new Thread(site,"003");
        t1.start();
        t2.start();
        t3.start();
    }
}
